<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('新增文件')" />
	<th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-fileMsg-add">
			<input id="id" name="id" type="hidden" th:value="${fileMsg.id}">
			<input id="parentId" name="parentId" type="hidden" th:value="${fileMsg.parentId}">
			<input id="fRepoId" name="fRepoId" type="hidden" th:value="${fileMsg.fRepoId}">
			<!--<input id="enableVersion" name="enableVersion" type="text">-->
		</form>

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="busi:version:remove">
				<i class="fa fa-remove"></i> 删除
			</a>
		</div>
		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table"></table>
		</div>
	</div>


	<th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-fileinput-js" />
	<script th:inline="javascript">
        var prefix = ctx + "busi/file/version";
		var repoId = [[${fileMsg.fRepoId}]];
		var fileId = [[${fileMsg.id}]];
		var removeFlag = [[${@permission.hasPermi('busi:repository:remove')}]];

		$("#form-fileMsg-add").fileinput({'showUpload':false, 'previewFileType':'any'});

		function submitHandler() {
			$.modal.close();
		}

		$(function () {
			var options = {
				url: prefix + "/list/"+repoId+"/"+fileId,
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				modalName: "文件资源库",
				sortName: "createdTime",                         // 排序列名称
				sortOrder: "DESC",
				columns: [{
					checkbox: false
				},
					{
						field: 'id',
						title: 'ID',
						visible: false
					},
					{
						field: 'repoName',
						title: '仓库名称',
					},
					{
						field: 'repoDirect',
						title: '仓库文件夹'
					},
					{
						field: 'fileName',
						title: '文件名称'
					},
					{
						field: 'version',
						title: '文件版本'
					},
					{
						field: '_enable',
						title: '切换版本',
						formatter: function (value, row, index) {
							return statusTools(row);
						}
					},
					{
						field: 'createdTime',
						title: '创建时间'
					},
					{
						field: 'remark',
						title: '备注'
					},
					{
						title: '操作',
						align: 'center',
						witch: 400,
						formatter: function(value, row, index) {
							var actions = [];
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
							return actions.join('');
						}
					}]
			};
			$.table.init(options);
		});

		/* 状态显示 */
		function statusTools(row) {
			if (row._enable === "1") {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
			}
		}

		/* 启用 */
		function enable(id) {
			$.modal.confirm("确认要切换到此版本吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "_enable": 0});
			})
		}
		
		function disable() {
			$.modal.alertError("此版本正在使用不予许禁用");
		}
    </script>
</body>
</html>
